{extend name="admin@public/basic" /}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>
{/block}

{block name="cotent"}
<form class="layui-form">

    <!--顶部操作栏--开始-->
    <blockquote id="searchBlock" class="layui-elem-quote quoteBox">

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label-admin">酒店编号</label>
            <div class="layui-input-inline">
                <input type="text" id="hotel_num" class="layui-input" placeholder="请输入酒店编号"/>
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label-admin">酒店名称</label>
            <div class="layui-input-inline">
                <input type="text" id="name" class="layui-input" placeholder="请输入酒店名称"/>
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label-admin">酒店地址</label>
            <div class="layui-input-inline">
                <input type="text" id="address" class="layui-input" placeholder="请输入酒店地址"/>
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label-admin">联系电话</label>
            <div class="layui-input-inline">
                <input type="text" id="contact_tel" class="layui-input" placeholder="请输入联系电话"/>
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label-admin">创建时间</label>
            <div class="layui-input-inline">
                <input type="text" id="create_time" class="layui-input " placeholder="请选择创建时间" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <a class="layui-btn" data-search="currentTableId">搜索</a>
        </div>

        {if auth("$thisClass/add")}
        <div class="layui-form-item layui-inline">
            <a class="layui-btn layui-btn-normal" data-open='{:url("$thisClass/add")}' data-title="添加">添加</a>
        </div>
        {/if}

        {if auth("$thisClass/del")}
        <div class="layui-form-item layui-inline">
            <a class="layui-btn layui-btn-danger layui-btn-normal" data-title="确定删除？" data-del-all='{:url("$thisClass/del")}' data-table-id="currentTableId">删除</a>
        </div>
        {/if}
        <div class="layui-form-item layui-inline">
            <a class="layui-btn layui-btn-green" data-title="导出" href="javascript:;" id="backup">导出</a>
        </div>

    </blockquote>
    <!--顶部操作栏--结束-->

    <!--主表单渲染--开始-->
    <table id="currentTable" lay-filter="currentTable"></table>
    <!--主表单渲染--结束-->

    <!--表单模板绑定--开始-->
    <script type="text/html" id="bindMemberInfo">
        <div>
            <span>{{d.nickname}}</span> <a class="layui-btn layui-btn-xs color-admin-desc" data-open='{:url("@admin/article.member/detail")}?id={{d.member_id}}' data-title="查看会员信息" data-width="1000px" data-height="450px">{{d.username}}</a>
        </div>
    </script>

    <script type="text/html" id="bindImage">
        <img style="width: 60px; height: 40px;" src="{:CDNDomain()}{{d.image ? d.image : '/static/image/admin/face.png'}}" layer-src="{:CDNDomain()}{{d.image}}" alt="{{d.name}}" data-image="open" lay-filter="modifyHeadImg">
    </script>
    <!-- 启用禁用 -->
    <script type="text/html" id="checkStatus">
        <input type="checkbox" name="{{d.id}}" value="{{d.status}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="modifyStatus" {{ d.status== 1 ? 'checked' : '' }}>
    </script>
    <!-- 是否推荐 -->
        <script type="text/html" id="checkPosition">
            {{ d.is_pos== 0 ? '<span class="layui-badge-rim">否</span>' : '<span class="layui-badge-rim layui-bg-green">是</span>' }}
        </script>
    <!-- 是否删除 -->
    <script type="text/html" id="checkDeleted">
        {{ d.is_deleted== 0 ? '<span class="layui-badge-rim">否</span>' : '' }}
    </script>
    <!--表单模板绑定--结束-->

    <!--表单操作栏--开始-->
    <script type="text/html" id="currentTableBar">



        {if auth("$thisClass/edit")}
        <a class="layui-btn layui-btn-xs" data-open='{:url("$thisClass/edit")}?id={{d.id}}' data-title="修改信息">编辑</a>
        {/if}

        {if auth("$thisClass/del")}
        <a class="layui-btn layui-btn-xs layui-btn-danger" data-title="确定删除？" data-del='{:url("$thisClass/del")}?id={{d.id}}'>删除</a>
        {/if}

    </script>
    <!--表单操作栏--结束-->

</form>
{/block}

{block name="script"}
<script>

    /**
     * 生成表单
     */
    $.form.table('current', '{:url("$thisRequest")}?type=ajax', [[
        {type: 'checkbox', width: 50, fixed: 'left'},
        {field: 'id', title: '酒店ID',align: 'center'},
        {field: 'hotel_num', title: '酒店编号',align: 'center'},
        {field: 'name', title: '酒店名称',align: 'center'},
        {field: 'province_text', title: '所属省份',align: 'center'},
        {field: 'city_text', title: '所属城市',align: 'center'},
        {field: 'address', title: '酒店地址',align: 'center'},
        {field: 'contacts', title: '联系人',align: 'center'},
        {field: 'contact_tel', title: '联系电话',align: 'center'},
        {field: 'new_create_time', title: '创建时间',align: 'center'},
        {field: 'is_boss', title: '绑定Boss',align: 'center'},
        {field: 'status', title: '开业状态',align: 'center',width: 110, templet: '#checkStatus', unresize: true},
        {field: 'commission', title: '佣金比',align: 'center'},
        {field:'id',title: '操作', minWidth: 160, templet: '#currentTableBar', fixed: 'right', align: 'center'},
    ]], true, 'line', 'lg', true);
    /**
     * 日期范围
     */
    $.laydate.range('create_time');


    /**
     * 修改状态
     */
    $.form.switch('modifyStatus', '{:url("$thisClass/status")}');

    /**
     * 门店数据导出为Excel
     */
    $(document).on("click", "#backup", function () {
        var searchData = Array();
        var searchInput = $('#searchBlock div div input');
        var searchSelect = $('#searchBlock div div select');
        $.each(searchInput, function (i, obj) {
            id = $(obj).attr('id');
            if (id != undefined) {
                searchData[id] = $("#" + id).val();
            }
        });
        $.each(searchSelect, function (i, obj) {
            id = $(obj).attr('id');
            if (id != undefined) {
                searchData[id] = $("#" + id).val();
            }
        });
        var flag = new Date().getTime();

        var search = searchData;

        var page=1;
        layer.load(2,{shade: [0.5,'#fff']});
        layer.msg('正在准备导出,请耐心等待',{time: 5000});
        explorecel(page,search,flag);

    });
    function explorecel(page,search,flag) {
        $.get('{:url("$thisClass/export")}',
        {
            page:page,
            search:search,
            flag:flag,
        },
        function(data){
            layer.msg(data.msg);
            if(data.code==0){
                if(data.allpage+1>data.page){
                    setTimeout(function () {
                        explorecel(data.page,search,flag);
                    },1400)
                }else {
                    layer.closeAll();
                    window.location.href = '{:url("setting.store/export")}?flag='+flag+'&page='+data.page+'&search='+search;
                }
            } else {
                setTimeout(function () {
                    layer.closeAll();
                },1400)
            }
        }, "json");
    }

    // $('#backup').click(function (){
    //     $.msg.tips('正在发送导出请求,请稍候...',1.5);
    //     $.msg.confirm('是否导出门店信息',function(){
    //         window.location.href="{:url('@admin/setting.store/import_msg')}";
    //         return false;
    //     },function(){
    //         $.msg.tips('导出取消',1.5);
    //         return false;
    //     });
    // });
</script>
{/block}
